package com.xxs.interceptor;

import org.apache.commons.lang3.StringUtils;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;

public class AdminInterceptor implements Interceptor {
    @Override
    public void intercept(Invocation inv) {
        Controller controller = inv.getController();
        String newPath = StringUtils.substringBeforeLast(inv.getViewPath(), "/");
        String modelName = StringUtils.substringAfterLast(newPath, "/");
        if(modelName!=null && modelName.equals("model")){
        	System.out.println("修改前的modelName:"+controller.getPara(1));
//        	modelName = controller.getPara(0);
        	System.out.println("修改后的modelName:"+modelName);
        }
        controller.setAttr("modelName", modelName);
        inv.invoke();
//        Admin user = WebUtils.currentUser(controller);
//        if (user != null && Const.ADMIN_EMAIL.equals(user.getStr("email"))){
//            inv.invoke();
//        }else{
//            controller.setAttr("msg", "需要管理员权限");
//            controller.render("/admin/login.html");
//            //controller.renderError(500);
//        }
    }
    
}
